﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ValidationFramework
{
	public class TypeKey
	{
		public RuntimeTypeHandle TypeHandle { get; set; }

        public Type TargetType 
        {
            get
            {
                return Type.GetTypeFromHandle(TypeHandle);
            }
        }

        /// <summary>
		/// Initializes a new instance of the TypeKey class.
		/// </summary>
		public TypeKey(RuntimeTypeHandle typeHandle)
		{
			TypeHandle = typeHandle;
		}
		/// <summary>
		/// Initializes a new instance of the TypeKey class.
		/// </summary>
		public TypeKey(Type type)
		{
			TypeHandle = type.TypeHandle;
		}
		
		// --- To support using as a dictionary key
		public override bool Equals(object obj)
		{
			var key = (TypeKey)obj;
			return this.TypeHandle.Equals(key.TypeHandle);
		}

		public override int GetHashCode()
		{
			//TODO: this is probably a poor hash algorithm. Its probably ok, but if we can come up with a better one replace this.
			return TypeHandle.GetHashCode();
		}
	}
}
